package com.hxy.subject.domain.handler.subject;

import com.hxy.subject.domain.entity.SubjectInfoBO;
import com.hxy.subject.infra.basic.entity.SubjectRadio;
import com.hxy.subject.infra.basic.service.SubjectRadioService;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author haoxuyang
 * @Date 2024/9/8 20:08
 */
public class Radio implements SubjectInfoTypeHandler {

    @Resource
    private SubjectRadioService subjectRadioService;
    @Override
    public String getHandlerType() {
        return "1";
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        List<SubjectRadio> list = new ArrayList<>();
        if (CollectionUtils.isEmpty(subjectInfoBO.getOptionList())){
            return;
        }
        for (SubjectInfoBO.option option : subjectInfoBO.getOptionList()) {
            SubjectRadio subjectRadio = new SubjectRadio();
            subjectRadio.setSubjectId(subjectRadio.getSubjectId());
            subjectRadio.setOptionType(option.getOptionType());
            subjectRadio.setOptionContent(option.getOptionContent());
            subjectRadio.setIsCorrect(option.getIsCorrect());
            subjectRadio.setCreatedTime(new Date());
            subjectRadio.setUpdateTime(new Date());
            subjectRadio.setIsDeleted(1);
            list.add(subjectRadio);
        }
        if (!CollectionUtils.isEmpty(list)){
            subjectRadioService.insertBatch(list);
        }

    }
}
